<template>
	<view class="questions">
		<view class="questions_title" v-if="quesList.title">
			{{quesList.title}}
		</view>
		<view class="questions_time" v-if="quesList.createTime">
			{{quesList.createTime}}
		</view>
		<view class="questions_con" v-if="quesList.content">
			{{quesList.content}}
		</view>
		<view class="imgquestions">
			<image :src="url+'uploadPath/question/'+quesList.file_name" mode=""></image>
		</view>
		<view class="questions_utitle">
			请输入题目答案：
		</view>
		<uni-section>
			<view class="example-body">
				<uni-file-picker limit="10" ref="files" :auto-upload="false" @select="select" @delete="del"
					v-model="one">
				</uni-file-picker>
			</view>
		</uni-section>
	<!-- 	<view class="questions_utitle">
			通过图片上传答案：
		</view>
		<view class="example-body">
			<uni-file-picker limit="1" ref="files" :auto-upload="false" @select="select" @delete="del" v-model="one">
			</uni-file-picker>
		</view> -->
		<view class="bottom_btn">
			<view class="bottom_btn_min">
				<!-- <view class="bottom_btn_left" @click="up()">
					上一题
				</view> -->
				<view class="bottom_btn_right" @click="nextclick()">
					提交答案
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				one: [
				
				],
				two: [],
				quesList:'',
				numindex:'',
				arrlist:[],
				numone:'',
				url:''
			}
		},

			onLoad(e){
			this.numindex=e.index
			this.quesList=JSON.parse(e.item)
			uni.setStorageSync('quesList', JSON.parse(e.item));
		},
		mounted() {
			this.url=this.$formalUrl
			this.$http({
				url: "answer/answerStatus?questionId="+this.quesList.id+'&userId='+uni.getStorageSync('Id'),
				method: 'POST',	
				
			}).then((res) => {
				if(res.code==200){
					res.data.imgs.forEach((item)=>{
					item.url=this.$formalUrl+'uploadPath/'+item.filePath
				})
				this.one=res.data.imgs
				console.log(this.one,'00000000000')
				}
				
			})
		// 	console.log(this.$formalUrl,'+________________________________')
		},
		methods:{
			async select(e) {
				console.log(e,'+___+++')
				if (e.tempFilePaths) {
					console.log("e.tempFilePaths有值了");
					e.tempFilePaths.forEach((item) => {
						const tempFilePaths = item
						const accessToken = uni.getStorageSync('accessToken') || '';
						uni.uploadFile({
							url: this.url+'answer/save?qid='+this.quesList.id+'&userId='+uni.getStorageSync('Id')+'&content='+this.quesList.content, //上传图片的后端接口
							filePath: tempFilePaths,
							name: 'file',
							header: {
								token: accessToken
							},
							// formData:{
							// 	qid:'1646719228706099202'||this.quesList.id,
							// 	userId:'1646695701966524418'||uni.getStorageSync('Id'),
							// 	// content:this.quesList.content,
							// },
							success: res => {
								this.numone=res.statusCode
								console.log(this.numone,'___')
								if(res.statusCode==200){
									uni.showToast({
										title: '上传成功',
										icon: 'success'
									});
								}
								// let test = JSON.parse(res.data)
								// let obj = {
								// 	ideaPath: test.url,
								// 	ideaName: e.tempFiles[0].name
								// }
								// this.picList.push(obj)
								// console.log("success", test.url)
							},
							fail: res => {
								console.log("fail", res)
							},
							complete: res => {
								console.log("头像", res)
							}
						})
					})
				}
				
			},
			up(){
				if(this.numindex<=0){
					this.numindex=0
					uni.showToast({
						title: '无上一页',
						icon: 'none'
					});
				}else{
					this.$refs.files.clearFiles()
					this.numindex=this.numindex-1
					console.log(this.numindex,'1一题')
					this.arrlist=uni.getStorageSync('questionList')
						this.arrlist.forEach((item)=>{
						if(this.numindex==item.index){
							this.quesList=item						
						}
					})
					// uni.showToast({
					// 	title: '无上一页',
					// 	icon: 'none'
					// });
				}
				
			},
			nextclick(){
				console.log(this.numone)
				if(this.numone==200){
					this.numone=''
					// if(this.numindex!==this.arrlist.length-1){
					// this.$refs.files.clearFiles()
					// this.numindex++
					// console.log(this.numindex,'下一题')
					// this.arrlist=uni.getStorageSync('questionList')
					// this.arrlist.forEach((item)=>{
					// if(this.numindex==item.index){
					// 	this.quesList=item						
					// }
				// })
				uni.switchTab({
					url: "../../pages/news/index",
				});
				// }else{
				// 		console.log(this.arrlist.length,this.numindex,'____')
				// 		uni.showToast({
				// 		title: '无下一页',
				// 		icon: 'none'
				// 	});
					
					
				
				// }
				}else{
					if(this.one.length>0){
						uni.showToast({
							title: '请上传新答案',
							icon: 'none'
						});
					}else{
						uni.showToast({
							title: '答案不能为空',
							icon: 'none'
						});
					}
					
				}
				
				
				
				
			}
					
		}
	}
</script>

<style lang="scss">
	.questions {
		padding: 47rpx;

		.questions_title {
			font-size: 40rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #2A3447;
		}

		.questions_time {
			margin-top: 25rpx;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #7B7E8F;
		}

		.questions_con {
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #7B7E8F;
			line-height: 40rpx;
			margin-top: 30rpx;
		}

		.questions_utitle {
			margin: 26rpx 0;
		}
		.bottom_btn{
			margin-top: 50rpx;
			.bottom_btn_min{
				justify-content: center;
				display: flex;
				width: 100%;
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				.bottom_btn_left{
					width: 305rpx;
					height: 104rpx;
					background: #3B72EC;
					border-radius: 4rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				.bottom_btn_right{
					width: 305rpx;
					height: 104rpx;
					background: #3B72EC;
					border-radius: 4rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
	}
.imgquestions{
	margin: 10rpx 0;
	image{
		width: 100%;
	}
}
	::v-deep {
		.uni-section .uni-section-header {
			display: none !important;
		}

		.uni-easyinput__content-textarea {
			font-size: 28rpx !important;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999999;
			line-height: 40rpx;
			height: 325rpx !important;
		}

		.uni-section {
			background: #F6F7F9 !important;
			border-radius: 24rpx !important;

		}

		.icon-add {
			background-color: #575B66 !important;
			width: 50rpx !important;
			height: 4rpx !important;
		}

		.is-add {
			background-color: #E7E7E7;
		}
	}
</style>